/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.io.*;
import java.util.Calendar;
import java.text.SimpleDateFormat;

/**
 * Class used to print information on a txt to track bugs
 *
 * @author Yati
 */
public class BugTracker {
    
    private File bugTracker=new File("BugTracker.txt");
    private FileOutputStream fos;
    private PrintStream out;

    final String format ="yyyy-MM-dd HH:mm:ss";
    Calendar cal;
    SimpleDateFormat sdf;

    
    public BugTracker(){
        init();
    }

    private void init(){

        cal=Calendar.getInstance();
        sdf= new SimpleDateFormat(format);
        try{
            fos=new FileOutputStream(bugTracker,true);
            out=new PrintStream(fos);

        }catch(IOException e){
            System.err.println("Failed to create bug tracker!");
        }

        writeToFile("/********************\n" +
                     "       Bug Tracker - "+insertTimeDate()+"   \n" +
                     "********************/\n");
        writeToFile("Session started");
    }

    public void writeToFile(String info){

        out.println(info);
        out.println();
    }

    public String insertTimeDate(){
        return sdf.format(cal.getTime());
    }

    public void stop(){
        writeToFile("Session ended");
        out.close();
    }

}
